package top.kaoshanji.ch03;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.math.BigInteger;
import java.util.Scanner;

/**
 * 代码清单 ch03-06：一个大数示例(抽奖2)
 * author kaoshanji
 * ^_^
 * create time 2024/11/24 10:15
 */
public class BigIntegerTest {

    private static final Logger logger = LogManager.getLogger(BigIntegerTest.class);

    public static void main(String[] args) {
        logger.info("...代码清单 ch03-06：一个大数示例(抽奖2)...");

        Scanner in = new Scanner(System.in);

        System.out.print("How many numbers do you need to draw?(中奖数字的位数)");
        int k = in.nextInt();

        System.out.print("What is the highest number you can draw?(中奖数字可选的总数)");
        int n = in.nextInt();


        BigInteger lotteryOdds = BigInteger.valueOf(1);

        for (int i = 1; i <= k; i++) {
            lotteryOdds = lotteryOdds.multiply(BigInteger.valueOf(n - i + 1)).divide(BigInteger.valueOf(i));
        }

        System.out.println("Your odds are 1 in " + lotteryOdds + ". Good luck!");

    }

}
